package other.acm;

import java.lang.reflect.Array;
import java.util.Scanner;

public class poj1469 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Integer readcishu = scan.nextInt() ;
		Integer [] result = new Integer [readcishu]; //存储结果
		Integer arraysize = 0;
		
		for (int i=0 ;i < readcishu ;i++){
			arraysize = scan.nextInt()*2;
			Integer [] st = new Integer[arraysize];
			for (int j =0 ; j<st.length ;j++ ){
				st[j]= scan.nextInt();
				//System.out.println("st"+j+":"+st[j]);
			}		
			Integer [] tempst = new Integer[2];
			
			for (int m=0 ; m< arraysize ; m=m+2 ){
				for (int  k=0 ; k<arraysize - m ;k=k+2){
					if(k+2 < arraysize){
						if (st[k] > st[k+2] ){
							int a = st[k];
							int b = st[k+1];
							st[k]= st[k+2];
							st[k+1]=st[k+3];
							st[k+2]=a;
							st[k+3]=b;	

						}else if(st[k] == st[k+2]){
							if(st[k+1] > st[k+3]){
								int c = st[k+1];
								st[k+1]=st[k+3];
								st[k+3]=c;
							}						
						}else{
							
						}			
					}
				}
			}
			
//			for (int h=0 ; h<st.length ;h++ ){
//				System.out.print(st[h]);
//				System.out.println();
//			}
			
			int ci = 0;
			
			ci =getlines(st ,arraysize ,ci);
			//System.out.println(ci);
			result[i] = ci;		
		}
		
		for(int x=0 ; x<result.length;x++ ){
			System.out.println(result[x]);
		} 

	}
	
	public static int  getlines(Integer [] stnew ,Integer arraysize ,Integer linenums){

		
		for (int t=0 ; t<stnew.length ;t=t+2){						
			if(t+3  < arraysize){
					if( stnew[t+1] > stnew[t+3] ){
						
					}else{
						stnew[t]= -1;
						stnew[t+1]= -1;
						//stnew[t+2]= -1;
						//stnew[t+3]= -1;
					}
			}else{
				if(stnew[t-1] == -1 ){
					stnew[t]= -1;
					stnew[t+1]= -1;
				}
			}			
		}
		int  j =0 ;
		for ( int m =0 ; m< arraysize ; m++){
			if (stnew[m]!= -1 ){
				j++;				
			}
		}
		j++;
		Integer []  temp = new Integer[j];
		
		int  n =0 ;
		for( int i =0 ; i< arraysize ; i++){
			if (stnew[i]!= -1 ){
				temp[n] = stnew[i];
				n++;				
			}			
		}		
		
		if(temp[0] == null ||temp[0].equals("") ){
			
		}else{
			linenums = getlines(temp ,j,linenums);
		}		
		return linenums +1 ;		
	}	
	
}
